﻿@using MvcCheckBoxList.Model
@model BMS.ViewModels.QuotationInvoiceModel
@using System.Globalization

@{
    ViewBag.Title = "Invoice";
}

@section featured {
    <section class="featured">
        <div class="content-wrapper" align="center">
            <hgroup class="title">
                <h1>@ViewBag.Message</h1>
            </hgroup>
        </div>
    </section>
}

@*@using (Html.BeginForm("Index", "Invoice", FormMethod.Get))
{
    <p align="center">
        Find by Quotation No: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
        <input type="submit" value="Search" />
    </p>
}*@

@using (Html.BeginForm())
{
    <div align="center">
        <table align="center" border="0">
            <tr>
                <td align="right" width="300">@Html.Label("Billing FM") @Html.DropDownList("FMNameSV", Model.fmList, "", new { style = "width:150px", @maxlength = "150" })</td>
                <td align="center">&nbsp;</td>
                <td align="right" width="300">@Html.LabelFor(model => model.invoiceModel.InvoiceNo) @Html.TextBoxFor(model => model.invoiceModel.InvoiceNo, new { style = "width:150px", @maxlength = "150" })</td>
            </tr>
            @*<tr>
                <td align="left" width="250">&nbsp;</td>
                <td align="center">&nbsp;</td>
                <td align="right" width="250">@Html.Label("Invoice Type") @Html.DropDownList("InvoiceType", Model.targetList, "", new { style = "width:150px", @maxlength = "200", onchange = "$('form').action = 'InvoiceSelectiob'; $('form').submit();" })</td>
            </tr>*@
            <tr>
                <td align="right" width="300">@Html.Label("Quo No") @Html.TextBoxFor(model => model.invoiceModel.QuotNo, new { style = "width:150px", @maxlength = "150" })</td>
                <td align="center">&nbsp;</td>
                <td align="right" width="300">@Html.Label("DN No") @Html.TextBoxFor(model => model.invoiceModel.DNNo, new { style = "width:150px", @maxlength = "150" })</td>
            </tr>
            <tr>
                <td align="right" width="300">@Html.Label("PO No") @Html.TextBoxFor(model => model.invoiceModel.PONo, new { style = "width:150px", @maxlength = "150" })</td>
                <td align="center">&nbsp;</td>
                <td align="right" width="300">@Html.Label("WO No") @Html.TextBoxFor(model => model.invoiceModel.WONo, new { style = "width:150px", @maxlength = "150" })</td>
            </tr>
        </table>
    </div>
    <br />

    <fieldset>
        <div align="center">
            <table border="0">
                <tr>
                    <td align="left" width="250">@Html.Label("FM Filter") @Html.DropDownList("FMNameFilter", Model.fmListForFiltering, new { style = "width:150px", @maxlength = "150" })</td>
                    <td align="center">&nbsp;</td>
                    <td align="right" width="300">&nbsp;</td>
                </tr>
            </table>

            <br />

            <table border="0">
                <thead>
                    <tr>
                        <th align="center" width="250">Available Quotations</th>
                        <th align="center">&nbsp;</th>
                        <th align="center" width="250">Requested Quotations</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td align="center" valign="top">
                            @Html.ListBoxFor(model => model.AvailableSelected, new MultiSelectList(Model.AvailableQuotaionsSelectedList, "QuotationNo", "QuotationNo", Model.AvailableSelected), new { id = "AvailableList", size = "10", style = "width:75%;" })
                        </td>
                        <td align="center" valign="top">
                            <input type="submit" name="add" id="add" value="Add >>" /><br />
                            <input type="submit" name="remove" id="remove" value="<< Remove" />
                        </td>
                        <td align="center" valign="top">
                            @Html.ListBoxFor(model => model.RequestedSelected, new MultiSelectList(Model.RequestedQuotaionsSelectedList, "QuotationNo", "QuotationNo", Model.RequestedSelected), new { id = "RequestedList", size = "10", style = "width:75%;" })
                        </td>
                    </tr>
                </tbody>
            </table>
            <br />
            @Html.HiddenFor(model => model.SavedRequested)

            @if (Model.RequestedQuotaionsSelectedList.Count > 0)
            {
                <fieldset style="width: 600px;">
                    <legend>Confirmed Invoice</legend>
                    <table align="left" border="1" id="tblQuotations">
                        <thead>
                            <tr>
                                <th align="center" width="100">Input Date</th>
                                <th align="center" width="200">Quotation No</th>
                                <th align="center" width="150">PO Amount (HK$)</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <td colspan="2">&nbsp;</td>
                                <td align="center"><span id="total" style="font-weight:bold;">@Model.RequestedTotal.ToString("#,##0.00")</span></td>
                            </tr>
                        </tfoot>
                        <tbody id="tableBody">
                            @foreach (var item in Model.RequestedQuotaionsSelectedList)
                            {
                                <tr>
                                    <td align="center">@item.QuotationCreationDate.ToString("yyyy-MMMM-dd", CultureInfo.CreateSpecificCulture("en-US"))</td>
                                    <td align="center">@item.QuotationNo</td>
                                    <td align="center">@item.TotalAmount.ToString("#,##0.00")</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                    <table align="right" border="0">
                        <input type="submit" name="confirm" id="confirm" value="Confirm" />
                    </table>

                </fieldset>
            }
        </div>
    </fieldset>
}

<section>
    @using (Html.BeginForm("BackToMainMeun", "Home"))
    {
        <br align="center" />
        <input type="submit" value="Back To Main Menu" />
    }
</section>

@section scripts {
    <script type="text/javascript" src="~/Scripts/jquery-2.0.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var names = $('#AvailableList option').clone();

            $('#FMNameFilter').change(function () {
                var val = $(this).val();
                $('#AvailableList').empty();
                names.filter(function (idx, el) {
                    return val === 'All' || $(el).text().indexOf(val + '-') >= 0;
                }).appendTo('#AvailableList');
            });
        });
    </script>
}